package middleware

import (
	"context"

	v1 "helloworld/api/helloworld/v1"

	"github.com/go-kratos/kratos/v2/transport/http"
)

func sayHelloHandler(ctx http.Context) error {
	var in v1.LoginRequest
	if err := ctx.BindQuery(&in); err != nil {
		return err
	}

	// binding /hello/{name} to in.Name
	if err := ctx.BindVars(&in); err != nil {
		return err
	}

	http.SetOperation(ctx, "/helloworld.Greeter/SayHello")
	h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
		return &v1.LoginResponse{AccessToken: "test:" + req.(*v1.LoginRequest).Code}, nil
	})
	return ctx.Returns(h(ctx, &in))
}
